package mobileapps.examples;

import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.TextView;
import android.widget.Toast;

public class LocationActivity extends Activity {
    /** Called when the activity is first created. */
	private LocationManager lm;
	TextView tv;
    private LocationListener locationListener;
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = new TextView(this);
        
        lm = (LocationManager) 
        getSystemService(Context.LOCATION_SERVICE);    
    
    locationListener =  new MyLocationListener();
    
    lm.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, 
        0, 
        0, 
        locationListener);   
    
 
    
    }
    private class MyLocationListener implements LocationListener
    {
      //  @Override
        public void onLocationChanged(Location loc) {
            if (loc != null) {
               Toast.makeText(getBaseContext(), 
                    "Location changed : Lat: " + loc.getLatitude() + 
                    " Lng: " + loc.getLongitude(), 
                   Toast.LENGTH_LONG).show();
               tv.setText("Location changed : Lat: " + loc.getLatitude() + 
                       " \nLng: " + loc.getLongitude());
               setContentView(tv);  
            }
        }

       // @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        }

       // @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
        }

       // @Override
        public void onStatusChanged(String provider, int status, 
            Bundle extras) {
            // TODO Auto-generated method stub
        }
    }        
    
}

